/*  1:   */ package org.jetbrains.jps.model.impl;
/*  2:   */ 
/*  3:   */

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.*;
import org.jetbrains.jps.model.ex.JpsCompositeElementBase;
import org.jetbrains.jps.model.ex.JpsElementChildRoleBase;

import java.util.List;

/*  4:   */
/*  5:   */
/*  6:   */
/*  7:   */
/*  8:   */
/*  9:   */
/* 10:   */
/* 11:   */
/* 12:   */
/* 13:   */
/* 14:   */
/* 15:   */ 
/* 16:   */ public abstract class JpsNamedElementReferenceBase<S extends JpsNamedElement, T extends JpsNamedElement, Self extends JpsNamedElementReferenceBase<S, T, Self>>
/* 17:   */   extends JpsCompositeElementBase<Self>
/* 18:   */   implements JpsElementReference<T>
/* 19:   */ {
/* 20:31 */   private static final JpsElementChildRole<JpsElementReference<? extends JpsCompositeElement>> a = JpsElementChildRoleBase.create("parent");
/* 21:   */   protected final String myElementName;
/* 22:   */   
/* 23:   */   protected JpsNamedElementReferenceBase(@NotNull String paramString, @NotNull JpsElementReference<? extends JpsCompositeElement> paramJpsElementReference)
/* 24:   */   {
/* 25:36 */     this.myElementName = paramString;
/* 26:37 */     this.myContainer.setChild(a, paramJpsElementReference);
/* 27:   */   }
/* 28:   */   
/* 29:   */   protected JpsNamedElementReferenceBase(JpsNamedElementReferenceBase<S, T, Self> paramJpsNamedElementReferenceBase)
/* 30:   */   {
/* 31:41 */     super(paramJpsNamedElementReferenceBase);
/* 32:42 */     this.myElementName = paramJpsNamedElementReferenceBase.myElementName;
/* 33:   */   }
/* 34:   */   
/* 35:   */   public T resolve()
/* 36:   */   {
/* 37:47 */     JpsCompositeElement localJpsCompositeElement = (JpsCompositeElement)getParentReference().resolve();
/* 38:48 */     if (localJpsCompositeElement == null) {
/* 39:48 */       return null;
/* 40:   */     }
/* 41:50 */     JpsElementCollection localJpsElementCollection = getCollection(localJpsCompositeElement);
/* 42:51 */     if (localJpsElementCollection == null) {
/* 43:51 */       return null;
/* 44:   */     }
/* 45:53 */     List localList = localJpsElementCollection.getElements();
/* 46:54 */     for (JpsNamedElement localJpsNamedElement1 : localList) {
/* 47:55 */       if (localJpsNamedElement1.getName().equals(this.myElementName))
/* 48:   */       {
/* 49:56 */         JpsNamedElement localJpsNamedElement2 = resolve(localJpsNamedElement1);
/* 50:57 */         if (localJpsNamedElement2 != null) {
/* 51:58 */           return localJpsNamedElement2;
/* 52:   */         }
/* 53:   */       }
/* 54:   */     }
/* 55:62 */     return null;
/* 56:   */   }
/* 57:   */   
/* 58:   */   @Nullable
/* 59:   */   protected abstract JpsElementCollection<? extends S> getCollection(@NotNull JpsCompositeElement paramJpsCompositeElement);
/* 60:   */   
/* 61:   */   @Nullable
/* 62:   */   protected abstract T resolve(S paramS);
/* 63:   */   
/* 64:   */   public JpsElementReference<? extends JpsCompositeElement> getParentReference()
/* 65:   */   {
/* 66:72 */     return (JpsElementReference)this.myContainer.getChild(a);
/* 67:   */   }
/* 68:   */   
/* 69:   */   public JpsElementReference<T> asExternal(@NotNull JpsModel paramJpsModel)
/* 70:   */   {
/* 71:77 */     if (paramJpsModel == null) {
/* 72:77 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/jetbrains/jps/model/impl/JpsNamedElementReferenceBase", "asExternal" }));
/* 73:   */     }
/* 74:77 */     paramJpsModel.registerExternalReference(this);
/* 75:78 */     return this;
/* 76:   */   }
/* 77:   */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.jps.model.impl.JpsNamedElementReferenceBase

 * JD-Core Version:    0.7.0.1

 */